package com.jianbing.shasha.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jianbing.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.shasha.domain.ShashaUserAchieve;
import com.jianbing.shasha.service.IShashaUserAchieveService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * 用户获得奖励记录Controller
 * 
 * @author ruoyi
 * @date 2024-06-09
 */
@RestController
@RequestMapping("/shasha/achieve")
public class ShashaUserAchieveController extends BaseController
{
    @Autowired
    private IShashaUserAchieveService shashaUserAchieveService;

    /**
     * 查询用户获得奖励记录列表
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:achieve:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShashaUserAchieve shashaUserAchieve)
    {
        startPage();
        List<ShashaUserAchieve> list = shashaUserAchieveService.selectShashaUserAchieveList(shashaUserAchieve);
        return getDataTable(list);
    }

    /**
     * 导出用户获得奖励记录列表
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:achieve:export')")
    @Log(title = "用户获得奖励记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShashaUserAchieve shashaUserAchieve)
    {
        List<ShashaUserAchieve> list = shashaUserAchieveService.selectShashaUserAchieveList(shashaUserAchieve);
        ExcelUtil<ShashaUserAchieve> util = new ExcelUtil<ShashaUserAchieve>(ShashaUserAchieve.class);
        util.exportExcel(response, list, "用户获得奖励记录数据");
    }

    /**
     * 获取用户获得奖励记录详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:achieve:query')")
    @GetMapping()
    public AjaxResult getInfo()
    {
        Long userId = SecurityUtils.getUserId();
        return success(shashaUserAchieveService.selectShashaUserAchieveByUserId(userId));
    }

    /**
     * 新增用户获得奖励记录
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:achieve:add')")
    @Log(title = "用户获得奖励记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShashaUserAchieve shashaUserAchieve)
    {
        Long userId = SecurityUtils.getUserId();
        shashaUserAchieve.setUserId(userId);
        shashaUserAchieve.setInsertTime(new Date());
        return toAjax(shashaUserAchieveService.insertShashaUserAchieve(shashaUserAchieve));
    }

    /**
     * 修改用户获得奖励记录
     */
    //  @PreAuthorize("@ss.hasPermi('shasha:achieve:edit')")
    @Log(title = "用户获得奖励记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShashaUserAchieve shashaUserAchieve)
    {
        return toAjax(shashaUserAchieveService.updateShashaUserAchieve(shashaUserAchieve));
    }

    /**
     * 删除用户获得奖励记录
     */
    // @PreAuthorize("@ss.hasPermi('shasha:achieve:remove')")
    @Log(title = "用户获得奖励记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shashaUserAchieveService.deleteShashaUserAchieveByIds(ids));
    }
}
